package com.un.ebs.product.mapper;

import com.baomidou.mybatisplus.annotation.SqlParser;
import com.un.ebs.product.domain.ProductSku;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.un.ebs.product.domain.ProductSkuExt;
import com.un.ebs.product.domain.ProductSkuItemExt;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author liubo
 * @since 2019-09-16
 */
@Component
public interface ProductSkuMapper extends BaseMapper<ProductSku> {

    @SqlParser(filter = true)
    @Select("select top 1 * from v_product_sku_ext where id=#{id} and is_delete=0 and spu_is_delete=0")
    ProductSkuExt selectNotTenantIdById(@Param("id") String id);

    @SqlParser(filter = true)
    @Select("select top 1 * from v_product_sku_ext where product_id=#{spuId} and sale_attr_desc=#{saleAttr} and is_delete=0 and spu_is_delete=0")
    ProductSkuExt selectNotTenant(@Param("spuId") String spuId, @Param("saleAttr") String saleAttr);

    @SqlParser(filter = true)
    @Select("select top 1 * from v_product_sku_ext where product_id=#{spuId} and (LEN(replace(sale_attr_desc,' ',''))=0 OR sale_attr_desc IS NULL) and is_delete=0 and spu_is_delete=0")
    ProductSkuExt selectNotTenantBySpu(@Param("spuId") String spuId);

    @SqlParser(filter = true)
    @Select("select top 1 * from v_product_sku_ext where qrcode=#{qrcode}")
    ProductSkuExt selectByQrcode(@Param("qrcode") String qrcode);

    @SqlParser(filter = true)
    @Select("select count(*) from v_product_sku_item_ext where include_sku_id = #{skuId}")
    List<ProductSkuItemExt> selectItemCountBySku(@Param("skuId") String skuId);

}
